#pragma once
#pragma warning(push)
#pragma warning(disable:4251)

#include <vector>
using namespace std;
#include "UIWindowBase.h"

class CUICaptionButton;
//class CUINcFrame;
class CUIGridImgPlus;
class CUIMenu;

class COOLUI_CLASS CUIFrame : public CUIWindowBase
{
public:
    CUIFrame( HWND hWnd );

    virtual ~CUIFrame();

    LRESULT ProcessUIMsg( UINT uMsg, WPARAM wParam, LPARAM lParam );

    void AddCaptionButton( CUICaptionButton* pCapBtn );

    void SetFrameMargin( int iLeft, int iTop, int iRight, int iBottom );

    void SetFrameCaptionImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount );

    void SetFrameLeftImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount );

    void SetFrameRightImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount );

    void SetFrameBottomImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount );

    void SetFrameBkImg( LPCTSTR lpszImg, IMGDIRECTION imgdir = IMG_HOR, UINT imgCount = 1 );

    void SetCloseBtnImg( LPCTSTR lpszImg, IMGDIRECTION imgdir = IMG_HOR, UINT imgCount = 1 );

    void SetMaxBtnImg( LPCTSTR lpszImg, IMGDIRECTION imgdir = IMG_HOR, UINT imgCount = 1 );

    void SetMinBtnImg( LPCTSTR lpszImg, IMGDIRECTION imgdir = IMG_HOR, UINT imgCount = 1 );
protected:

    CUICaptionButton* HitTestButton( const POINT& pt );

    void InvalidCapBtns();

    LRESULT HandNcHitTest( const POINT& pt );

    void ReDrawFrame();

    LRESULT OnNcPaint();

    LRESULT OnNcHitTest( WPARAM wParam, LPARAM lParam, LRESULT lRet );

    LRESULT OnNcLButtonDown( WPARAM wParam, LPARAM lParam );

    LRESULT OnNCLButtonUp( WPARAM wParam, LPARAM lParam );

    LRESULT OnNcActive( WPARAM wParam, LPARAM lParam );

    LRESULT OnSize( WPARAM wParam, LPARAM lParam );

    LRESULT OnEraseBkgnd( WPARAM wParam, LPARAM lParam );

    LRESULT OnNcCalcSize( WPARAM wParam, LPARAM lParam );

    LRESULT OnInitMenuPopup( WPARAM wParam, LPARAM lParam );

    LRESULT OnMeasureItem( WPARAM wParam, LPARAM lParam );

    LRESULT OnDrawItem( WPARAM wParam, LPARAM lParam );

    LRESULT OnWindowPosChanging( WPARAM wParam, LPARAM lParam );

    LRESULT OnNcMouseMove( WPARAM wParam, LPARAM lParam );

    LRESULT OnNcMouseLeave( WPARAM wParam, LPARAM lParam );

private:

    void RemoveSysCapButton();

    void RemoveFrameBorder();

    vector<CUICaptionButton*> m_vecCapBtn;

    int m_iFrameWidth;
    int m_iFrameHeight;
    int m_iFrameBorderWidth;
    int m_iFrameBorderHeight;
    int m_iFrameCaptionHeight;
    int m_iOldCapHeight;

    CUIGridImgPlus* m_pFrameCaption;
    CUIGridImgPlus* m_pFrameLeft;
    CUIGridImgPlus* m_pFrameRight;
    CUIGridImgPlus* m_pFrameBottom;

    CUIGridImgPlus* m_pFrameBK;

    BOOL m_bFrameActive;

    CUIMenu* m_pPopupMenu;
    CUICaptionButton* m_pHotCapBtn;
    CUICaptionButton* m_pPressCapBtn;

    CUICaptionButton* m_pMax;
    CUICaptionButton* m_pMin;
    CUICaptionButton* m_pClose;
};

#pragma warning(pop)